package com.woody.aggregate.domain.saas;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.ChainWrappers;
import com.woody.aggregate.infrastructure.saas.entity.SaasShopConfig;
import com.woody.aggregate.infrastructure.saas.mapper.SaasShopConfigMapper;
import com.woody.aggregate.saas.vo.SaasShopConfigVO;
import com.woody.aggregate.shop.enums.ParentShopShowStatusEnum;
import com.woody.aggregate.shop.enums.ParentShopShowTypeEnum;
import com.woody.aggregate.shop.enums.ShopShowTypeEnum;
import com.woody.common.web.util.JacksonUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * &copy; All rights Reserved
 *
 * @author wénkǎi.zhāng
 */
@Component
public class SaasShopConfigManager extends ServiceImpl<SaasShopConfigMapper, SaasShopConfig> {

    /**
     * 根据主门店id查询商圈配置
     *
     * @param shopId
     * @return
     */
    public Optional<SaasShopConfig> getByShopId(Long shopId) {
        if (shopId == null) {
            return Optional.empty();
        }
        SaasShopConfig saasShopConfig = ChainWrappers.lambdaQueryChain(getBaseMapper()).eq(SaasShopConfig::getShopId, shopId).one();
        return Optional.ofNullable(saasShopConfig);
    }

    /**
     * 根据主门店id批量查询商圈配置
     *
     * @param shopIds
     * @return
     */
    public List<SaasShopConfig> getByShopIds(Collection<Long> shopIds) {
        if (CollectionUtils.isEmpty(shopIds)) {
            return Collections.emptyList();
        }
        return ChainWrappers.lambdaQueryChain(getBaseMapper()).in(SaasShopConfig::getShopId, shopIds).list();
    }

    /**
     * 查询默认商圈配置
     *
     * @return
     */
    public static SaasShopConfig getDefaultConfig() {
        SaasShopConfig config = new SaasShopConfig();
        config.setChildShopShowType(ShopShowTypeEnum.BD.getType());
        config.setParentShopShow(ParentShopShowStatusEnum.SHOW.getStatus());
        config.setParentShopShowType(ParentShopShowTypeEnum.BD.getType());

        return config;
    }



}
